package com.lrkj.property.controller;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.property.domain.OwnerDoor;
import com.lrkj.property.service.IOwnerDoorService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 业主门禁Controller
 *
 * @author yajun_ren
 * @date 2021-08-18
 */
@RestController
@RequestMapping("/property/door")
public class OwnerDoorController extends BaseController
{
    @Autowired
    private IOwnerDoorService ownerDoorService;

    /**
     * 查询业主门禁列表
     */
    @ApiOperation(value = "查询业主门禁列表", notes = "查询业主门禁列表")
    @PreAuthorize("@ss.hasPermi('property:door:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnerDoor ownerDoor)
    {
        startPage();
        List<OwnerDoor> list = ownerDoorService.selectOwnerDoorList(ownerDoor);
        return getDataTable(list);
    }

    /**
     * 导出业主门禁列表
     */
	@ApiOperation(value = "导出业主门禁列表", notes = "导出业主门禁列表")
    @PreAuthorize("@ss.hasPermi('property:door:export')")
    @Log(title = "业主门禁", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnerDoor ownerDoor)
    {
        List<OwnerDoor> list = ownerDoorService.selectOwnerDoorList(ownerDoor);
        ExcelUtil<OwnerDoor> util = new ExcelUtil<OwnerDoor>(OwnerDoor.class);
        return util.exportExcel(list, "业主门禁数据");
    }

    /**
     * 获取业主门禁详细信息
     */
	@ApiOperation(value = "获取业主门禁详细信息", notes = "获取业主门禁详细信息")
    @PreAuthorize("@ss.hasPermi('property:door:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(ownerDoorService.selectOwnerDoorById(id));
    }

    /**
     * 新增业主门禁
     */
	  @ApiOperation(value = "新增业主门禁", notes = "新增业主门禁")
    @PreAuthorize("@ss.hasPermi('property:door:add')")
    @Log(title = "业主门禁", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnerDoor ownerDoor)
    {
        return toAjax(ownerDoorService.insertOwnerDoor(ownerDoor));
    }

    /**
     * 修改业主门禁
     */
	 @ApiOperation(value = "修改业主门禁", notes = "修改业主门禁")
    @PreAuthorize("@ss.hasPermi('property:door:edit')")
    @Log(title = "业主门禁", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnerDoor ownerDoor)
    {
        return toAjax(ownerDoorService.updateOwnerDoor(ownerDoor));
    }

    /**
     * 删除业主门禁
     */
	 @ApiOperation(value = "删除业主门禁", notes = "删除业主门禁")
    @PreAuthorize("@ss.hasPermi('property:door:remove')")
    @Log(title = "业主门禁", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ownerDoorService.deleteOwnerDoorByIds(ids));
    }
}
